import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/contact_us/ctrl.dart';
import 'package:url_launcher/url_launcher_string.dart';

class ContactUsPage extends StatelessWidget {
  ContactUsPage({super.key});

  final ctrl = Get.put(ContactUsCtrl());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.Pure_gray_bg,
      appBar: CustomAppBar(
        title: const Text('联系我们', style: TextStyle(fontSize: 17)),
        showAlarmButton: false,
      ),
      body: GetBuilder(
        init: ctrl,
        builder: (_) {
          return Column(
            children: [
              _buildMap(),
              // AppGaps.vGap10,
              _buildContact(),
            ],
          );
        },
      ),
    );
  }

  Widget _buildMap() {
    return Container(
      height: 10.w,
      // decoration: const BoxDecoration(
      //   color: Colors.white,
      //   borderRadius: BorderRadius.only(
      //     bottomLeft: Radius.circular(10),
      //     bottomRight: Radius.circular(10),
      //   ),
      //   boxShadow: [
      //     BoxShadow(
      //       color: Colors.black12,
      //       offset: Offset(0, 2),
      //       blurRadius: 4,
      //     ),
      //   ],
      // ),
      // child: const Center(
      //   child: Text('地图'),
      // ),
    );
  }

  Widget _buildContact() {
    return Expanded(
      child: Container(
        color: Colors.white,
        child: Column(
          children: [
            _buildContactItem(
              icon: Icons.location_on,
              title: '详细地址',
              content: '四川省成都市成华区成致路多元总部国际1号2栋',
              onTap: () {
                launchUrlString('geo:latitude,longitude');
              },
            ),
            Divider(height: 1.w, color: AppColors.bg_color_grey),
            _buildContactItem(
              icon: Icons.phone,
              title: '联系电话',
              content: '400-123-4567',
              onTap: () {
                launchUrlString('tel:4001234567');
              },
            ),
            Divider(height: 1.w, color: AppColors.bg_color_grey),
            _buildContactItem(
              icon: Icons.email,
              title: '联系邮箱',
              content: '',
              onTap: () {
                launchUrlString('mailto:');
              },
            ),
            Divider(height: 1.w, color: AppColors.bg_color_grey),
            const Spacer(),
            _buildDial(),
            AppGaps.vGap60,
          ],
        ),
      ),
    );
  }

  Widget _buildContactItem({
    required IconData icon,
    required String title,
    required String content,
    required VoidCallback onTap,
  }) {
    return InkWell(
      onTap: onTap,
      child: Container(
        height: 50.w,
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: 15.w),
        child: Row(
          children: [
            Icon(icon, size: 19.sp),
            AppGaps.hGap10,
            Text(
              title,
              style: const TextStyle(
                height: 1.2,
                fontSize: 16,
              ),
            ),
            AppGaps.hGap20,
            Expanded(
              child: Container(
                alignment: Alignment.centerRight,
                child: Text(
                  content,
                  style: const TextStyle(
                    fontSize: 16,
                    height: 1.2,
                    color: AppColors.text_grey,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// 拨打电话
  Widget _buildDial() {
    return Container(
      decoration: BoxDecoration(
        color: AppColors.blue_button,
        borderRadius: BorderRadius.circular(25),
      ),
      padding: const EdgeInsets.symmetric(horizontal: 27, vertical: 11),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          const Icon(
            Icons.phone,
            color: Colors.white,
          ),
          AppGaps.hGap10,
          const Text('电话咨询', style: TextStyle(color: Colors.white))
        ],
      ),
    );
  }
}
